<!--
* description: 技术援助单回复
* author:shensai
* createdDate: 2021.1.26
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-show-more-btn="true"
      :callback-obj="callbackObj"
    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />

    <look
      :key="lookPopupsKey"
      :dynamic-edit-row-data="editRowData1"
      :popups-visible="editPopupsVisible1"
      :popups-state="editPopupsState1"
      :dynamic-api-style="'restful'"
      @close="close1"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import { vehiclePdiPriceInquirys } from '@/api/se/vehiclePdiPriceInquiry'
import api from '@/api/subsidyManage'

import edit from './edit'
import look from './look'

import Vue from 'vue'
export default {
  name: 'TechnicalReply',
  components: {
    OneTableTemplate,
    edit,
    look
  },
  mixins: [oneTableWithViewTemplateMixins],
  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData(
      [to.path, 'supplierMessage-edit'],
      () => {
        next()
      }
    )
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      titleName: '',
      editRowData: {},
      editRowData1: {},
      editPopupsState: '',
      editPopupsState1: '',
      editPopupsVisible: false,
      editPopupsVisible1: false,
      lookPopupsKey: 'lookPopupsKey',
      // 网格查询API配置对象
      apiConfig: vehiclePdiPriceInquirys.findList,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          name: 'search', // 按钮图标样式
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey4',
          type: '',
          size: 'small',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          name: 'reset',
          position: 'right' // 重置
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 显示组件

            {
              compKey: 'compKey1',
              labelName: '申请编号：',
              codeField: 'applyCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '门店编号：',
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '门店名称：',
              codeField: 'dlrShortName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: 'VIN：',
              codeField: 'vin',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '主题：',
              codeField: 'faultTopic',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            },
            {
              compKey: 'compKey6',
              labelName: '申请人：',
              codeField: 'apply',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            },
            {
              compKey: 'compKey7',
              labelName: '申请日期：',
              codeField: 'applyStartDate,applyEndDate',
              component: () =>
                import('@/components/org/datePicker/andtDatePicker'),
              type: 'YYYY-MM-DD',
              // dataToObject: { timer: true, thirtyTime: true, hhmmss: true },
              format: 'yyyy-MM-dd',
              isMust: false
            },
            {
              compKey: 'compKey8',
              labelName: '状态：',
              codeField: 'status',
              component: () => import('@/components/org/commonSelect'),
              oFields: 'claimStatusCode,claimStatusName',
              type: 'dropdownList',
              options: [
                { claimStatusCode: '1', claimStatusName: '提交' },
                { claimStatusCode: '2', claimStatusName: '回复' },
                { claimStatusCode: '3', claimStatusName: '申请关闭' },
                { claimStatusCode: '4', claimStatusName: '关闭' }
              ],
              isMust: false
            }
          ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'controlBtn1',
              label: '操作',
              minWidth: 180,
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '回复',
                  rowFileds: 'show:status-提交',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => this.edit(index)
                },
                {
                  compKey: 'propKey2',
                  labelName: '关闭',
                  rowFileds: 'show:status-申请关闭',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => this.hide(index)
                },
                {
                  compKey: 'propKey3',
                  labelName: '详情',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => this.look(index)
                }
              ]
            },
            {
              prop: 'appleyId',
              label: '申请ID',
              hidden: true
            },
            {
              prop: 'applyCode',
              label: '申请单号'
            },
            {
              prop: 'carConfigCn',
              label: '车系'
            },
            {
              prop: 'carSeriesCn',
              label: '车型'
            },
            {
              prop: 'dlrCode',
              label: '门店编码'
            },
            {
              prop: 'dlrShortName',
              label: '门店名称'
            },
            {
              prop: 'applyDate',
              label: '申请日期'
            },
            {
              prop: 'faultTopic',
              label: '主题'
            },
            {
              prop: 'replyName',
              label: '回复人'
            },
            {
              prop: 'status',
              label: '状态'
            }
          ],
      formField: {
        appleyId: '',
        applyCode: '',
        dlrCode: '',
        dlrFullName: '',
        vin: '',
        faultTopic: '',
        apply: '',
        applyStartDate: '',
        applyEndDate: '',
        status: ''
      },
      // 是否使用刷新Key的方式刷新弹窗
      resetDialogKey: false,
      // 单表格模版页面组件回调事件
      callbackObj: {
        // // 手动勾选时
        // onCheckSelect: (selection, row) => {
        //   // 清除所有选中
        //   this.$refs.multipleTable.$refs.multipleTable.clearSelection()
        //   if (selection.length === 0) return
        //   // 将当前点击项选中
        //   this.$refs.multipleTable.$refs.multipleTable.toggleRowSelection(row, true)
        // },
        // // 当选择项发生变化时会触发该事件（多选时）
        // onCheckSelectChange: (selection) => {
        //   if (selection.length === 1) {
        //     this.editRowData = selection[0]
        //   }
        // }
      }
    }
  },
  mounted() {
    this.queryTable(1)
  },
  methods: {
    close() {
      this.editPopupsVisible = false
      this.queryTable(1)
    },
    close1() {
      this.editPopupsVisible1 = false
      this.queryTable(1)
    },
    edit(index, popstatus) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$refs['multipleTable'].list[index]
    },
    look(index) {
      this.editPopupsState1 = 'look'
      this.editPopupsVisible1 = true
      this.editRowData1 = this.$refs['multipleTable'].list[index]
    },
    // 关闭按钮
    hide(index) {
      const appleyId = this.$refs['multipleTable'].list[index].appleyId
      const queryObj = {
        // 保存mutation
        type: 'mutation',
        // api配置
        apiConfig: api.close,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: { appleyId: appleyId }
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）

      this.$confirm('确定关闭吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.$requestAPI(paramD).then((response) => {
          if (response.result === '1') {
            // this.queryTable();
            this.$message('关闭成功')
          } else {
            // 作废失败
            this.$message({
              message: response.msg,
              type: 'warn',
              duration: 1000
            })
          }
          this.queryTable(1)
        })
      })
    }
  }
}
</script>
